package com.group.sliding.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.group.sliding.exception.BadRequestException;
import lombok.Getter;

@Getter
public enum PayStatus {
    NOT_COMMIT(1, "待提交"),
    WAIT_BUYER_PAY(2, "待支付"),
    TRADE_CLOSED(3, "支付超时/取消"),
    TRADE_FINISHED(4, "支付成功");

    @EnumValue
    @JsonValue
    private final int value;
    private final String desc;

    PayStatus(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static PayStatus of(int value) {
        switch (value) {
            case 1:
                return NOT_COMMIT;
            case 2:
                return WAIT_BUYER_PAY;
            case 3:
                return TRADE_CLOSED;
            case 4:
                return TRADE_FINISHED;
            default:
                throw new BadRequestException("支付状态错误");
        }
    }
}